/*
 * This file (RxFilter.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package alkwarel.objects;

import java.awt.Color;

/**
 * Roxame Filters
 * 
 * @author Xavier Gouchet
 * 
 */
public abstract class RxFilter extends AkFilter {

	/** Hue */
	protected int hhue;

	/** Saturation */
	protected int ssat;

	/** Brightness (Value) */
	protected int vval;

	/** Color */
	protected int coulref;

	/**
	 * Standard Constructor.
	 * 
	 * @param id
	 *            the object's id
	 * @param name
	 *            the object's name
	 */
	public RxFilter(int id, String name) {
		super(id, name,null);
	}
	
	/**
	 * Standard Constructor.
	 * 
	 * @param id
	 *            the object's id
	 * @param name
	 *            the object's name
	 * @param requirements
	 *            the actuator's requirements
	 */
	public RxFilter(int id, String name, String[] requirements) {
		super(id, name, requirements);
	}

	/**
	 * @see alkwarel.objects.AkFilter#Apply(alkwarel.objects.AkArtspace)
	 */
	public abstract boolean Apply(AkArtspace a);

	/**
	 * Uses private HSV values to create a RGB color.
	 * 
	 */
	protected final void HSVRGB() {
		float h = ((float) this.hhue) / 360.0f;
		float s = ((float) this.ssat) / 1000.0f;
		float v = ((float) this.vval) / 255.0f;
		this.coulref = Color.HSBtoRGB(h, s, v);
	}

	/**
	 * Converts provided color to private HSV Values.
	 * 
	 * @param color
	 *            the color
	 */
	protected final void RGBHSV(int color) {
		int r = (color >> 16) & 0xff;
		int g = (color >> 8) & 0xff;
		int b = color & 0xff;
		float[] hsbvals = new float[3];
		Color.RGBtoHSB(r, g, b, hsbvals);
		this.hhue = (int) (hsbvals[0] * 360);
		this.ssat = (int) (hsbvals[1] * 1000);
		this.vval = (int) (hsbvals[2] * 255.0f);
	}

	/**
	 * Sets the hue
	 * 
	 * @param h
	 *            new hue value
	 */
	protected final void H(int h) {
		this.hhue = h;
	}

	/**
	 * Sets the saturation
	 * 
	 * @param s
	 *            new sat value
	 */
	protected final void S(int s) {
		this.ssat = s;
	}

	/**
	 * Sets the value
	 * 
	 * @param v
	 *            new value value
	 */
	protected final void V(int v) {
		this.vval = v;
	}

	/**
	 * @param c
	 *            a color
	 * @return the red component of the input color
	 */
	protected final int red(int c) {
		return (c >> 16) & 0xff;
	}

	/**
	 * @param c
	 *            a color
	 * @return the green component of the input color
	 */
	protected final int green(int c) {
		return (c >> 8) & 0xff;
	}

	/**
	 * @param c
	 *            a color
	 * @return the blue component of the input color
	 */
	protected final int blue(int c) {
		return c & 0xff;
	}
}
